<template>
	<div>
		<div class="outer">
			<a-form :label-col="{span: 3}" :wrapper-col="{span: 14}">
				<div class="w-100 b-b m-b-30 m-t-20 font-20 padding-b-5">微信公众号</div>
				<a-form-item label="appID">
					<a-input v-model:value="formData.weChat.common.appID" />
				</a-form-item>
				<a-form-item label="appsecret">
					<a-input v-model:value="formData.weChat.common.appsecret" />
				</a-form-item>
				<a-form-item label="token">
					<a-input v-model:value="formData.weChat.common.token" />
				</a-form-item>
				<a-form-item label="网站域名">
					<a-input v-model:value="formData.weChat.common.host" />
				</a-form-item>

				<div class="w-100" style="background-color: #f5f5f5;height: 5px;"></div>
				<div class="w-100 b-b m-b-30 m-t-20 font-20 padding-b-5">微信开放平台</div>

				<a-form-item label="Appid">
					<a-input v-model:value="formData.weChat.web.Appid" />
				</a-form-item>
				<a-form-item label="AppSecret">
					<a-input v-model:value="formData.weChat.web.AppSecret" />
				</a-form-item>
				<a-form-item label="回调地址">
					<a-input v-model:value="formData.weChat.web.redirect_uri" />
					<span class="font-12">回调地址，前端处理登录状态页面</span>
				</a-form-item>

				<div class="w-100" style="background-color: #f5f5f5;height: 5px;"></div>
				<div class="w-100 b-b m-b-30 m-t-20 font-20 padding-b-5">七牛云</div>
				<a-form-item label="accessKey">
					<a-input v-model:value="formData.qiniu.accessKey" />
				</a-form-item>
				<a-form-item label="secretKey">
					<a-input v-model:value="formData.qiniu.secretKey" />
				</a-form-item>
				<a-form-item label="bucket">
					<a-input v-model:value="formData.qiniu.bucket" />
				</a-form-item>
				<a-form-item label="CDN域名">
					<a-input v-model:value="formData.qiniu.host" />
				</a-form-item>
				
				<div class="w-100" style="background-color: #f5f5f5;height: 5px;"></div>
				<div class="w-100 b-b m-b-30 m-t-20 font-20 padding-b-5">上传配置</div>
				<a-form-item label="图片上传地址">
					<a-input v-model:value="formData.uploadPath.uploadPath" />
				</a-form-item>
				<a-form-item label="文件上传地址">
					<a-input v-model:value="formData.uploadPath.fileUploadPath" />
				</a-form-item>
				<a-form-item label="静态资源地址">
					<a-input v-model:value="formData.uploadPath.staticPath" placeholder="静态资源地址，七牛云CDN地址" />
				</a-form-item>
				<a-form-item label="后台图片上传地址">
					<a-input v-model:value="formData.uploadPath.adminUploadPath" />
				</a-form-item>

				<a-form-item :wrapper-col="{ span: 14, offset: 3 }">
					<a-button type="primary" @click="onSubmit">保存</a-button>
				</a-form-item>
			</a-form>
		</div>
	</div>
</template>

<script>
	import systemApi from '../../api/system.js'
	
	export default {
		data() {
			return {
				formData: {
					weChat: {
						web: {
							Appid: '',
							AppSecret: '',
							redirect_uri: 'https://xxx.com/user/wx-login'
						},
						common: {
							appID: '',
							appsecret: '',
							token: '',
							host: ''
						}
					},
					qiniu: {
						accessKey: '',
						secretKey: '',
						bucket: '',
						host: ''
					},
					uploadPath: {
						uploadPath: '',
						fileUploadPath: '',
						staticPath: '',
						adminUploadPath: ''
					}
				}
			}
		},
		mounted() {
			this.getSystemConfig()
		},
		methods: {
			onSubmit() {
				systemApi.systemConfig(this.formData, 'systemConfig').then(res => {
					if(res.status == 1){
						this.$message.success('修改成功')
					}
				})
			},
			getSystemConfig() {
				systemApi.getSystemConfig('systemConfig').then(res => {
					if(res.status == 1){
						this.formData = res.result
					}
				});
			},
		}
	}
</script>

<style scoped>
</style>